def validate_id(user_id):
    if len(user_id) > 8:
        return False
    for char in user_id:
        if not (char.isalnum() or char == '_'):
            return False
    return True

def validate_email(email):
    if '@' not in email or '.' not in email:
        return False
    at_index = email.index('@')
    dot_index = email.rindex('.')
    if at_index > dot_index:
        return False
    if at_index == 0 or dot_index == len(email) - 1:
        return False
    return True

def validate_id_number(id_number):
    if len(id_number) != 18:
        return False
    if not id_number[:-1].isdigit():
        return False
    return True

def get_gender(id_number):
    gender_digit = int(id_number[-2])
    return "男" if gender_digit % 2 == 1 else "女"

def validate_name(name):
    if len(name) > 4:
        return False
    for char in name:
        if not ('\u4e00' <= char <= '\u9fff'):
            return False
    return True

def main():
    user_id = input("请输入ID（不超过8位，只能由数字、字母、下划线组成）：")
    while not validate_id(user_id):
        user_id = input("ID不合法，请重新输入：")

    email = input("请输入EMAIL地址：")
    while not validate_email(email):
        email = input("EMAIL地址不合法，请重新输入：")

    id_number = input("请输入身份证号：")
    while not validate_id_number(id_number):
        id_number = input("身份证号不合法，请重新输入：")

    name = input("请输入姓名（只能中文且不能超过4位）：")
    while not validate_name(name):
        name = input("姓名不合法，请重新输入：")

    gender = get_gender(id_number)

    print("\n用户信息：")
    print(f"ID: {user_id}")
    print(f"EMAIL地址: {email}")
    print(f"身份证号: {id_number}")
    print(f"姓名: {name}")
    print(f"性别: {gender}")

if __name__ == "__main__":
    main()